#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/12/18 10:50
    Desc  :
--------------------------------------
"""
import xlrd
from flask import Blueprint, render_template, request
from application import app
from common.libs.JsonResponseUtils import JsonResponse
# from common.libs.RunCaseUtils import RunCaseUtils
from common.libs.paginationUtils import ListPaginationUtils
from common.libs.queryListUtils import QueryListUtils
from common.libs.ExcelUtils import ExcelUtils
from servers.models.CasesRecordModel import CasesRecord

case_record_route = Blueprint('case_record', __name__)


@case_record_route.route('/list', methods = ['POST'])
def caseRecordList():
    """
    用例测试记录列表
    :return:
    """
    try:
        form = {} if not request.json else dict(request.json)
        page, size = form.get('page'), form.get('size')
        form = QueryListUtils(form).filter_by('icontains')
        # 1. 获取当前项目id
        projectId = request.headers.get('project')
        form['projectId'] = projectId
        user = CasesRecord.objects(**form).order_by('-id')
        pagination = ListPaginationUtils(user, **form)
        return JsonResponse(code = 20000, data = pagination.items, message = '请求成功').jsonExit()
    except Exception as e:
        app.logger.error(e)
        return JsonResponse(code = 50000, data = None, message = "系统异常", errors = f'{e}').jsonExit()